package com.itheima.sc.web.sms;

import com.itheima.sc.pojo.sms.FlashPromotionProductRelation;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.sms.SmsFlashProductRelationService;
import com.itheima.sc.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/flashProductRelation")
public class SmsFlashProductRelationController {


    @Autowired
    private SmsFlashProductRelationService relationService;

    //批量添加
    @PostMapping("/create")
    public Result createProductRelation(@RequestBody List<FlashPromotionProductRelation> relations){
        relationService.addRelation(relations);
        return Result.success(null);
    }
    @PostMapping("/delete/{id}")
    public Result deleteProductRelation(@PathVariable("id")Long id){
        relationService.deleteRelation(id);
        return Result.success(null);
    }
    @GetMapping("/list")
    public Result productRelationList(@RequestParam Map<String,String> param){
        PageResult pageResult = relationService.productRelationList(param);
        return Result.success(pageResult);
    }
    @PostMapping("/update/{id}")
    public Result updateProductRelation(@PathVariable("id")Long id,@RequestBody FlashPromotionProductRelation relation){
         relationService.updateProductRelation(id,relation);
        return Result.success(null);
    }
    @GetMapping("/{id}")
    public Result getProductRelation(@PathVariable("id")Long id){
        FlashPromotionProductRelation relation= relationService.getProductRelation(id);
        return Result.success(relation);
    }
}
